package com.jiyun.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jiyun.user.domain.User;
import com.jiyun.user.openfeign.Feign;
import com.jiyun.user.service.UserService;
import com.jiyun.vo.Result;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import utils.JwtUtil;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
    @Autowired
    UserService userService;
    @Autowired
    Feign feign;

    @RequestMapping("login")
    public Result login(@RequestBody User user) {
        LambdaQueryWrapper<User> qw = new LambdaQueryWrapper<>();
        qw.eq(User::getUsername,user.getUsername());
        qw.eq(User::getPassword,user.getPassword());
        User one = userService.getOne(qw);
        if (one==null){
            return Result.errot();
        }
        Integer id = one.getId();
            String token = JwtUtil.getToken(id);
            log.info("token：{}",token);
            return  Result.seccuss(token);
    }
}
